//
//  FANAddPictureCell.m
//  Weibo - OC
//
//  Created by user on 16/4/27.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANAddPictureCell.h"
//#warning 宏定义一定要放到 导入头文件的 上面, 会影响编译

//define this constant if you want to use Masonry without the 'mas_' prefix

#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax

#define MAS_SHORTHAND_GLOBALS
#import <Masonry/Masonry.h>

@interface FANAddPictureCell ()

//@property (nonatomic, strong) UIButton *addButton;

@property (nonatomic, strong) UIImageView *addImageView;

@property (nonatomic, strong) UIButton *delectedButton;

@end

@implementation FANAddPictureCell

- (UIButton *)delectedButton{
    
    if (!_delectedButton) {
        
        _delectedButton = [[UIButton alloc] init];
        
        [_delectedButton setImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
        
        [_delectedButton addTarget:self action:@selector(didDelectedButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _delectedButton;
}

- (UIImageView *)addImageView{
    
    if (!_addImageView) {
        
        _addImageView = [[UIImageView alloc] init];
        
    }
    
    return _addImageView;
}


- (void)setImage:(UIImage *)image{
    
    _image = image;
    
    if (image == nil) {
        
        self.delectedButton.hidden = true;
        
        self.addImageView.image = [UIImage imageNamed:@"compose_pic_add"];
    
        
    }else{
        
        self.delectedButton.hidden = false;
        
        self.addImageView.image = image;
    }
}

- (void)didDelectedButton:(UIButton *)button{
    
    self.delectedBlock();
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
//    self.backgroundColor = [UIColor redColor];
    
    [self.contentView addSubview:self.addImageView];
    
    [self.contentView addSubview:self.delectedButton];
    
    [self.addImageView makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.contentView);
        
    }];
    
    [self.delectedButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.trailing.equalTo(self.contentView);
        
    }];
}

@end
